<?php
/**
 * @file test011.php
 * @package taobaoke
 * @subpackage 
 * @version $id: 0.1 UTF-8 2009-7-20 下午01:59:13 $
 * @author LD King (mifunny.info)
 * @copyright Copyright (c) 2007 - 2009 MiFunny China Inc. (http://mifunny.info)
 * 测试XMLRPC发布至Wordpress
 * 
 * 测试实现功能：
 * 1.发布; √
 * 2.中文，关键字，分类; √ √ √ 
 * 3.html标签; √ 
 * 4.文章缩略名; √ 
 * 5.预发布;
 * 6.自定义字段; √ 
 * 7.不同作者; √ 
 * 
 */
/*
 * wp_slug
 * wp_author_id
 * title 标题
 * description 内容 
 * mt_excerpt 摘要
 * mt_text_more
 * categories 分类，数组
 * mt_keywords 关键字
 * mt_allow_comments open 允许评论
 * mt_tb_ping_urls ping地址，数组
 * post_status pending 预发布
 * date_created_gmt
 * custom_fields 自定义字段，二维数组（'key'], $meta['value']);）
 * 
 * */
header("Content-Type:text/html;charset=UTF-8");
require_once '../lib/functions.php';

$mw = new xmlrpc_client(WP_XMLRPC);
//$mw->debug = true;

$content['post_type'] = 'post'; 
$content['title']="继续测试预发布074";
$content['wp_slug']='wp slug 预发布 ghost';
$content['categories'] = array("Study notes","本民经济");

$content['description']=file_get_contents("temp001");//"自定义字段 自定义字段 <br />自定义字段 自定义字段";

$content['mt_keywords']="关键字1,关键字2,关键字3";
$content['mt_allow_comments']="open";
$content['wp_author_id']="2";

//预发布
$content['post_status']="future";
//$timek = gmdate("Y-m-d H:i:s", mktime()+mt_rand(15,120) );   echo $timek;
/*$pktime = new IXR_Date( mktime()+180 );
$content['date_created_gmt']=$pktime->getXml();*/
$pktime = date('Ymd\TH:i:s\@', mktime()+180 );
$content['date_created_gmt']=$pktime ;
var_dump($pktime);

/*$gggg = new IXR_Date(time());
echo str_replace( 'Z', '', $gggg->getIso() ) . 'Z';*/


//自定义字段
$content['custom_fields']=array( array('key'=>'iid','value'=>'c2a890f27b0530cedef764e100488fa6'),
					array('key'=>'pic_url','value'=>'http://img05.taobaocdn.com/bao/uploaded/i5/T1ZB8iXoA_mdPXTHPb_093242.jpg'),
					array('key'=>'price','value'=>'45'));
/*$content['custom_fields']=array('iid'=>'c2a890f27b0530cedef764e100488fa6',
					'pic_url'=>'http://img05.taobaocdn.com/bao/uploaded/i5/T1ZB8iXoA_mdPXTHPb_093242.jpg',
					'price'=>45);*/
					

$x = new xmlrpcmsg("metaWeblog.newPost",
        array(php_xmlrpc_encode("1"),
        php_xmlrpc_encode(WP_USER),
        php_xmlrpc_encode(WP_PASS),
        php_xmlrpc_encode($content),
        php_xmlrpc_encode("1")));
       
//var_dump($x);
        
$mw->return_type = 'phpvals';
$r =$mw->send($x);
if ($r->errno=="0")
    echo "<br>".$content['title']."   Successfully Posted ";
else {
    echo "<br>There was an error";
    var_dump($r);
}





/**
 * IXR_Date
 *
 * @package IXR
 * @since 1.5
 */
class IXR_Date {
    var $year;
    var $month;
    var $day;
    var $hour;
    var $minute;
    var $second;
    var $timezone;
    function IXR_Date($time) {
        // $time can be a PHP timestamp or an ISO one
        if (is_numeric($time)) {
            $this->parseTimestamp($time);
        } else {
            $this->parseIso($time);
        }
    }
    function parseTimestamp($timestamp) {
        $this->year = date('Y', $timestamp);
        $this->month = date('m', $timestamp);
        $this->day = date('d', $timestamp);
        $this->hour = date('H', $timestamp);
        $this->minute = date('i', $timestamp);
        $this->second = date('s', $timestamp);
        // WP adds timezone. See #2036
        $this->timezone = '';
    }
    function parseIso($iso) {
        $this->year = substr($iso, 0, 4);
        $this->month = substr($iso, 4, 2);
        $this->day = substr($iso, 6, 2);
        $this->hour = substr($iso, 9, 2);
        $this->minute = substr($iso, 12, 2);
        $this->second = substr($iso, 15, 2);
        // WP adds timezone. See #2036
        $this->timezone = substr($iso, 17);
    }
    function getIso() {
    	// WP adds timezone. See #2036
        return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone;
    }
    function getXml() {
        return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>';
    }
    function getTimestamp() {
        return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
    }
}
?>